package com.sumainfor.pc.market.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.ActivityServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/2/15 17:20
 * @Description:
 */
@RestController
@RequestMapping("/activity")
public class ActivityContorller {

    @Autowired
    ActivityServiceImpl activityServiceImpl;

    /**
     * 功能描述: 
     * 创建活动
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/2/15 21:50
     */
    @ResponseBody
    @RequestMapping(value = "/AddActivity",method = RequestMethod.POST)
    public JsonResult AddActivity(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        if(activityServiceImpl.AddActivity(params)){
            result.putSuccess("活动创建成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述: 
     * 获取活动列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/2/15 21:51
     */
    @GetMapping("/getActivityList")
    public JsonResult getActivityList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        List<String> StatusList = new ArrayList<String>();
        StatusList.add("0");
        StatusList.add("1");
        StatusList.add("2");
        params.put("StatusList",StatusList);
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=activityServiceImpl.getActivityListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getActivityList=activityServiceImpl.getActivityList(params);
        result=pageUtils.getJsonResult(getActivityList, params, cout);
        return result;
    }

    /**
     * 功能描述: 
     * 根据编号获取活动详情
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/2/16 11:49
     */
    @GetMapping("/getActivity")
    public JsonResult getActivity(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ActId"})){
            result.putFailed("ActId不能为空！");
            return  result;
        }
        Map<String,Object>getActivity=activityServiceImpl.getActivity(params);
        result.put(getActivity);
        return result;
    }

    /**
     * 功能描述:
     * 根据活动编号修改活动资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/2/25 18:53
     */
    @ResponseBody
    @RequestMapping(value = "/UpActivity",method = RequestMethod.POST)
    public JsonResult UpActivity(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ActId"})){
            result.putFailed("ActId不能为空！");
            return  result;
        }
        if(activityServiceImpl.UpActivity(params)){
            result.putSuccess("活动保存成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述:
     * 根据活动编号修改活动资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/2/25 18:53
     */
    @ResponseBody
    @RequestMapping(value = "/UpActivityStatus",method = RequestMethod.POST)
    public JsonResult UpActivityStatus(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ActId"})){
            result.putFailed("ActId不能为空！");
            return  result;
        }
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"Status"})){
            result.putFailed("Status不能为空！");
            return  result;
        }
        if(activityServiceImpl.UpActivityStatus(params)){
            result.putSuccess("活动操作成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述:
     * 根据活动编号修改活动资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/2/25 18:53
     */
    @ResponseBody
    @RequestMapping(value = "/UpActivityTime",method = RequestMethod.POST)
    public JsonResult UpActivityTime(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ActId"})){
            result.putFailed("ActId不能为空！");
            return  result;
        }
        if(activityServiceImpl.UpActivityTime(params)){
            result.putSuccess("活动保存成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

}
